/*
 * @lc app=leetcode.cn id=1103 lang=javascript
 *
 * [1103] 分糖果 II
 */

// @lc code=start
/**
 * @param {number} candies
 * @param {number} num_people
 * @return {number[]}
 */
var distributeCandies = function (candies, num_people) {
  const res = Array(num_people).fill(0);
  let index = 0;
  let num = 1;
  while (candies) {
    if (candies <= num) {
      res[index] += candies;
      candies = 0;
      break;
    }
    candies -= num;
    res[index] += num;
    index++;
    num++;
    if (index >= num_people) {
      index = 0;
    }
  }
  return res;
};
// @lc code=end

